FORM FRM_DISPLAY.
CLEAR: GS_LAYOUT.

PERFORM FRM_LAYOUT.
IF P_SEL1 = 'X'.
    CLEAR:
    GT_FIELDCAT.
    PERFORM FRM_FIELDCAT.
    PERFORM FRM_OUTPUT.

    ELSEIF P_SEL2 = 'X'.

        CLEAR: GT_FIELDCAT.
        PERFORM FRM_FIELDCAT2.
        PERFORM FRM_OUTPUT2.
ENDIF.
ENDFORM.

FORM FRM_LAYOUT.
    GS_LAYOUT-ZEBRA = 'X'.
    GS_LAYOUT-CWIDTH_OPT = 'X'.
    GS_LAYOUT-BOX_FNAME = 'CHECK'.
    GS_LAYOUT-SEL_MODE = 'A'.
ENDFORM.

DEFINE INIT_FIELDCAT.
CLEAR GS_FIELDCAT.
GS_FIELDCAT-FIELDNAME = &1.
GS_FIELDCAT-COLTEXT = &2.
GS_FIELDCAT-EDIT = &3.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
END-OF-DEFINITION.

FORM FRM_FIELDCAT.
INIT_FIELDCAT 'SIGN' '导入标记' ''.
XXXXXXXXX
ENDFORM.

FORM FRM_OUTPUT.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
    I_CALLBACK_PROGRAM = SY-REPID
    I_CALLBACK_PF_STATUS_SET = 'ALV_STATUS'
    I_CALLBACK_USER_COMMAND = 'ALV_COMMAND'
    IS_LAYOUT_LVC = GS_LAYOUT
    IT_FIELD_LVC = GT_FIELDCAT
    TABLES
    T_OUTTAB = GT_ALV_DATA
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
ENDFORM.

XXXXXXXXXXX

FORM ALV_COMMAND USING PV_UCOMM LIKE SY-PV_UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.

DATA: LV_INDEX TYPE SY-TABIX.
DATA: LOB_GRID TYPE REF TO CL_GUI_ALV_GRID.

CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LOB_GRID.

CALL METHOD LOB_GRID->CHECK_CHANGED_DATA.
RS_SELFIELD-REFRESH = 'X'.
RS_SELFIELD-COL_STABLE = 'X'.
RS_SELFIELD-ROW_STABLE = 'X'.

DATA: LV_STEXT TYPE STRING.

CASE PV_UCOMM.
    WHEN 'ZIMPORT'.
        CLEAR UUID.
        UUID = CL_UUID_FACTORY=>CREATE_SYSTEM_UUID()->CREATE_UUID_X16()."生成uuid
        PERFORM DATA_PROCESS.

    WHEN 'ZADD'.
        CALL METHOD LOG_GRID->GET_FRONTEND_LAYOUT
        IMPORTING
        ES_LAYOUT = GS_LAYOUT.

        PERFORM APPEND_LINE.
    
    WHEN 'ZDELETE'.
        PERFORM DELETE_LINE.

    WHEN 'ZEDIT'.
    IF RS_SELFIELD-FIELDNAME IS NOT INITIAL AND RS_SELFIELD-TABINDEX IS NOT INITIAL.
        IF RS_SELFIELD-FIELDNAME <> 'SIGN' AND XXXXXXXX.
            IF P_SEL1 = 'X'.
                READ TABLE GT_ALV_DATA ASSIGNING <FS_DATA> INDEX RS_SELFIELD-TABINDEX.
                IF SY-SUBRC = 0.
                    ASSIGN COMPONENT RS_SELFIELD-FIELDNAME OF STRUCTURE <FS_DATA> TO <DYN_FIELD>.
                    LV_STEXT = <DYN_FIELD>.
                ENDIF.
            ENDIF.



            PERFORM EDIT USING LV_STEXT RS_SELFIELD-TABINDEX
            RS_SELFIELD-FIELDNAME.
        ENDIF.

    ELSE.
        MESSAGE '请选中需要更改的单元格' TYPE 'E'.
    ENDIF. 

    WHEN 'LOG'.
    PERFORM FRM_DISPLAY2.
ENDCASE.

RS_SELFIELD-REFRESH = 'X'.
CALL METHOD LOB_GRID->REFRESH_TABLE_DISPLAY.
ENDFORM.

FORM DELETE_LINE.
DATA: L_TOTAL TYPE STRING,
L_STXT TYPE STRING,
L_ANSWER TYPE C.

IF P_SEL1 = 'X'.
    REFRESH GT_DELETED.
    LOOP AT GT_ALV_DATA ASSIGNING <FS_DATA> WHERE CHECK = 'X'.
        CLEAR GS_ALV_DATA.
        MOVE-CORRESPONDING <FS_DATA> TO GS_ALV_DATA.
        APPEND GS_ALV_DATA TO GT_DELETED.
    ENDLOOP.
    DESCRIBE TABLE GT_DELETED LINES L_TOTAL.

    ELSEIF P_SEL2 = 'X'.
        XXXXXXXX
ENDIF.

CONCATENATE '已选中' L_TOTAL '条，确定要删除吗？（仅在显示中删除，不影响导入EXCEL文档中数据）' INTO L_STXT.
IF L_TOTAL = 0.
    MESSAGE '请至少选中一条数据' TYPE 'E'.
ENDIF.

CALL FUNCTION 'POPUP_CONTINUE_YES_NO'
EXPORTING
TEXTLINE1 = L_STXT
TITLE = '传输信息'
IMPORTING
ANSWER = L_ANSWER.

IF L_ANSWER = 'J'.
    IF P_SEL1 = 'X'.
        DELETE GT_ALV_DATA WHERE ('CHECK = "X"').
    ENDIF.
ELSEIF L_ANSWER = 'N'.
MESSAGE '已取消操作！' TYPE 'E'.
ENDIF.

ENDFORM.

FORM APPEND_LINE.
APPEND INITIAL LINE TO GT_ALV_DATA.
ENDFORM.

